/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.web.misc.license;

import java.util.Date;

public class LicenseInfo implements Cloneable {
    public String username;
    public int customerId = -1;
    public int productId;
    public int licenseId;
    public int majorVersion;
    public int minorVersion;
    public Date generationDate;
    public Date expirationDate;
//    public Date j;

    @Override
    public Object clone() {
        try {
            return super.clone();
        } catch (CloneNotSupportedException cnse) {
            cnse.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (!(obj instanceof LicenseInfo)) return false;

        LicenseInfo that = (LicenseInfo) obj;

        if (this.customerId != that.customerId) return false;
        if (this.licenseId != that.licenseId) return false;
        if (this.majorVersion != that.majorVersion) return false;
        if (this.minorVersion != that.minorVersion) return false;
        if (this.productId != that.productId) return false;
        if (this.expirationDate != null ? !this.expirationDate.equals(that.expirationDate) : that.expirationDate != null) {
            return false;
        }
        if (this.generationDate != null ? !this.generationDate.equals(that.generationDate) : that.generationDate != null) {
            return false;
        }
        if (this.username != null ? !this.username.equals(that.username) : that.username != null) {
            return false;
        }

        return true;
    }

    public int hashCode() {
        return this.username != null ? this.username.hashCode() : 0;
    }

    public String toString() {
        StringBuffer buff = new StringBuffer();
        buff.append("\n");
        buff.append("user name:" + this.username + "\n");
        buff.append("customer id:" + this.customerId + "\n");
        buff.append("product id:" + Products.getProductName(this.productId) + "\n");
        buff.append("license type:" + LicenseType.getLicenseType(this.licenseId) + "\n");
        buff.append("major version:" + this.majorVersion + "\n");
        buff.append("minor version:" + this.minorVersion + "\n");
        buff.append("generationDate:" + this.generationDate + "\n");
        buff.append("expirationDate:" + this.expirationDate + "\n");
        return buff.toString();
    }

}